<template>
  <div class="layout">
    <div class="comOnlineTrainDetail">
      <div style="display: flex; justify-content: space-between; margin-top: 20px">
        <Breadcrumb class="breadcrumb" :crumbs="crumbs"></Breadcrumb>
      </div>
      <div class="contentBox">
        <div class="leftDiv">
          <div class="topDiv">
            <div class="msgDiv">
              <div class="video-title">{{ video.companyTrain.title ? video.companyTrain.title : "无" }}</div>
              <div class="contentText">
                <div style="width: 44px">简介：</div>
                <template v-if="video.companyTrain.content">
									<pre v-html="video.companyTrain.content.replace(/<img/g,'<img style=max-width:100%;height:auto;').replace(/<p><img/g,'<img').replace(/\/img><\/p>/g,'/img>')"></pre>
								</template>
								<template v-else>无</template>
                <!-- <span style="width: 500px; word-wrap: break-word">
                  {{ video.companyTrain.content.replace(/<[^<>]+>/g, "") }}
                </span> -->
              </div>
            </div>
          </div>
          <vueVideoPlayerCom
            :src="video.companyTrain.video"
            :url="'comOnlineTrainDetail'"/>
          <div
            class="contentText feedbackText"
            v-if="video.companyTrain.feedback">
            <div style="width: 43px">反馈：</div>
            <span style="flex: 1; flex-wrap: wrap">{{`${video.companyTrain.feedback}; ${video.companyTrain.suggest}`}}</span>
          </div>
        </div>
        <div class="video-wrap">
          <div class="relativeVideo">相关视频</div>
          <div v-if="video.relate.length > 0">
            <relativeVideoFrame
              @refresh="goPage"
              class="videoFrame"
              v-for="(item, index) in video.relate"
              :video="item"
              :key="index"/>
          </div>
          <div class="no-data-tip" v-else>暂无相关视频</div>
        </div>
      </div>
      <Buttons @goBack="goBack" @feedback="feedback" :buttons="buttons"></Buttons>
        <!-- <div class="btn" @click="goBack">返回</div>
        <div
          class="btn"
          v-if="!video.companyTrain.feedback"
          :style="'background-color: #045db9; color: #FFFFFF'"
          @click="feedback">反馈</div> -->
    </div>
    <!-- 反馈弹出层 -->
    <feedbackDialog ref="DialogRef" :id="id" @refresh="refresh" />
  </div>
</template>

<script>
import Breadcrumb from "@/components/breadcrumb";
import relativeVideoFrame from "@/components/helpCom/relativeVideoFrame";
// api
import { getcomOnlineTrainDetail } from "@/common/api/company.js";
// 引用视频插件
import vueVideoPlayerCom from "@/components/vueVideoPlayerCom";
import feedbackDialog from "./feedbackDialog";
export default {
  name: "comOnlineTrainDetail",
  meta: {
    name: "视频培训（我的培训）详情页",
  },
  components: {
    Breadcrumb,
    relativeVideoFrame,
    vueVideoPlayerCom,
    feedbackDialog,
  },
  computed:{
    buttons(){
      let btns = [{text:"返回",type:"normal",size:"l",method:"goBack"}]
      if (!this.video.companyTrain.feedback) {
        btns.push({text:"反馈",type:"success",size:"l",method:"feedback"})
      }
      return btns;
    },
  },
  data() {
    return {
      crumbs: [
        {
          label: "企业空间",
          value: "companyMsg",
        },
        {
          label: "我的培训-视频培训",
          value: "companyMyTraining",
        },
        {
          label: "视频培训详情页",
          value: "comOnlineTrainDetail",
          choose: true,
        },
      ],
      id: null,
      video: {},
      loading: false, //加载状态
    };
  },
  mounted() {
    this.loading = true;
    this.getcomOnlineTrainDetail();
  },
  methods: {
    // 获取视频培训详情
    async getcomOnlineTrainDetail(id) {
      let ID = id ? id : this.$route.query.id;
      const { code, msg, data } = await getcomOnlineTrainDetail(ID);
      this.loading = false;
      if (code != "200") return this.$message.warning(msg);
      this.video = data;
    },
    // 反馈
    async feedback() {
      this.id = this.$route.query.id;
      this.$refs.DialogRef.dialogVisible = true;
    },
    // 点击相关视频 - 跳转企业帮扶视频详情
    goPage(id) {
      this.$router.push({ name: "onlineCourseDetail", query: { id } });
    },
    refresh() {
      this.getcomOnlineTrainDetail();
    },
    goBack() {
      this.$router.back();
    },
  },
};
</script>

<style lang="scss" scoped>
.layout {
  min-height: 100vh;
  position: relative;
  padding-bottom: 150px;
  box-sizing: border-box;
}
.btn-bottom {
  text-align: center;
  margin: 40px 0 150px;
}
.btn-bottom .cancelBtn {
  display: inline-block;
  font-size: 14px;
  background-color: #f1f2f4;
  color: #045db9;
  padding: 10px 46px;
  text-align: center;
  border-radius: 5px;
  margin-right: 10px;
}
.btn-bottom .cancelBtn:hover {
  border: 1px solid #eeeeee;
  cursor: pointer;
  box-shadow: 0px 0px 5px #eeeeee;
}

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
}

.comOnlineTrainDetail {
  width: $main-width;
  margin: 0 auto;
}

.comOnlineTrainDetail .contentBox {
  display: flex;
  width: 100%;
  margin: 20px 0 80px 0;
}

.comOnlineTrainDetail .leftDiv {
  width: 70%;
  text-align: left;
  margin-right: 42px;
}

.comOnlineTrainDetail .topDiv {
  /* margin-bottom: 25px; */
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
}

.comOnlineTrainDetail .topDiv .video-title {
  font-size: 24px;
  font-weight: bold;
  /* margin-bottom: 25px; */
  margin-bottom: 20px;

}

.comOnlineTrainDetail .contentText {
  width: 100%;
  /* display: flex; */
  color: #666666;
  text-align: left;
  font-size: 14px;
}

.comOnlineTrainDetail .feedbackText {
  margin-top: 10px;
}

.comOnlineTrainDetail .topDiv .sendBtn {
  width: 120px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  border: 1px solid #eee;
  color: #666666;
  font-size: 14px;
  border-radius: 3px;
  transition: all 0.2s ease 0s;
}

.comOnlineTrainDetail .topDiv .sendBtn:hover {
  cursor: pointer;
  box-shadow: 0px 0px 10px #eeeeee;
}

.comOnlineTrainDetail .videoImg {
  width: 100%;
  height: 506px;
}

.comOnlineTrainDetail .video-wrap {
  flex: 1;
  height: 100%;
}

.relativeVideo {
  border-left: 4px solid #045db9;
  font-size: 18px;
  height: 18px;
  line-height: 18px;
  color: #045db9;
  text-align: left;
  padding-left: 10px;
  margin-bottom: 8px;
}

.no-data-tip {
  background-color: #f8f8f8;
  font-size: 12px;
  color: #999999;
  text-align: center;
  height: 30px;
  line-height: 30px;
  margin-top: 15px;
}

	.btnDiv {
    margin-top: 20px;
		display: flex;
    justify-content: center;
    margin-bottom: 20px;
		/* justify-content: right; */
		/* justify-content: flex-end; */
		/* margin-left: 200px; */
	}

	.btnDiv div {
		background-color: #f1f2f4;
		color: #045db9;
		/* padding: 10px 30px; */
		font-size: 15px;
		border-radius: 5px;
		transition: all 0.2s ease 0s;
	}

  .btnDiv div:nth-child(1) {
    margin-right: 20px;
  }

	.btnDiv .btn {
		width: 100px;
		height: 40px;
		line-height: 40px;
		padding: 0;
		text-align: center;
	}

	.btnDiv div:hover {
		box-shadow: 0px 3px 5px #e1e1e1;
		cursor: pointer;
	}
</style>